<?php
/**
 * 检查数据库中的 Vendor2 数据
 */

echo "========== 检查数据库中的 Vendor2 数据 ==========\n\n";

try {
    // 数据库配置
    $host = '172.25.221.196';
    $db = 'flownetys';
    $user = 'flownetys';
    $pass = '63pF5HAnX3wK3maY';
    $port = 3306;

    // 创建 PDO 连接
    $pdo = new PDO(
        "mysql:host={$host};port={$port};dbname={$db};charset=utf8",
        $user,
        $pass,
        [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
    );

    // 查询最近的 Vendor2 数据
    $imei = '861179035726231';

    echo "【查询条件】\n";
    echo "- IMEI: {$imei}\n";
    echo "- 表名: flow_wifi_imei\n";
    echo "- 数据库: {$db}\n\n";

    // 查询数据
    $sql = "SELECT * FROM flow_wifi_imei WHERE IMEI = ?";
    $stmt = $pdo->prepare($sql);
    $stmt->execute([$imei]);
    $data = $stmt->fetchAll(PDO::FETCH_ASSOC);

    if ($data) {
        echo "【查询结果】✅ 找到 " . count($data) . " 条记录\n\n";

        foreach ($data as $index => $row) {
            echo "记录 " . ($index + 1) . ":\n";
            foreach ($row as $key => $value) {
                echo "  - {$key}: " . (is_array($value) ? json_encode($value) : $value) . "\n";
            }
            echo "\n";
        }
    } else {
        echo "【查询结果】❌ 未找到相关数据\n\n";

        // 尝试查询所有数据
        echo "【尝试查询所有数据】\n";
        $sql2 = "SELECT * FROM flow_wifi_imei ORDER BY id DESC LIMIT 5";
        $stmt2 = $pdo->prepare($sql2);
        $stmt2->execute();
        $allData = $stmt2->fetchAll(PDO::FETCH_ASSOC);

        if ($allData) {
            echo "最近 5 条记录:\n";
            foreach ($allData as $index => $row) {
                echo "  " . ($index + 1) . ". IMEI: " . ($row['IMEI'] ?? 'N/A') . ", MAC: " . ($row['mac'] ?? 'N/A') . ", 更新时间: " . ($row['update_time'] ?? 'N/A') . "\n";
            }
        } else {
            echo "表中没有任何数据\n";
        }
    }
    
    echo "\n========== 检查完成 ==========\n";
    
} catch (\Throwable $e) {
    echo "❌ 异常: " . $e->getMessage() . "\n";
    echo $e->getTraceAsString() . "\n";
    exit(1);
}

